<template>
  <div>
    <h2>用户投资页面</h2>
    投资项目名称:<input type="text" v-model="sdate.T_Name" />
    <input type="button" value="查询" @click="Show()" />
    <input type="button" value="排序" @click="paiss()" />
    <table class="table table-bordered">
      <thead>
        <tr>
          <td>投资ID</td>
          <td>投资项目名称</td>
          <td>总额度</td>
          <td>已投金额</td>
          <td>剩余额度</td>
          <td>投资次数</td>
        </tr>
      </thead>
      <tbody>
        <tr v-for="a in plist">
          <td>{{ a.T_Id }}</td>
          <td>{{ a.T_Name }}</td>
          <td>{{ a.T_Zong }}</td>
          <td>{{ a.T_Yi }}</td>
          <td>{{ a.T_Sheng }}</td>
          <td>{{ a.T_Age }}</td>
        </tr>
      </tbody>
    </table>
    <span>
      <input type="button" value="首页" @click="y('a')" />
      <input type="button" value="上一页" @click="ye('a')" />
      <input type="button" value="下一页" @click="ye('b')" />
      <input type="button" value="尾页" @click="y('b')" />
    </span>
    <span>
      <input type="text" v-model="cou" size="2" />
      <input type="button" value="go" @click="go()" />
    </span>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
let router = useRouter();
let route = useRoute();
import { useStore } from '../../store/user';
let user = useStore();

let data: any = reactive({
  sdate: {
    T_Name: '',
    index: 1,
    size: 2,
    pai: 1,
  },
  count: 0,
  pcount: 0,
  plist: {},
  cou: '',
});

let { sdate, count, pcount, plist, cou } = toRefs(data);
const paiss = () => {
  if (sdate.value.pai == 1) {
    sdate.value.pai = 2;
    Show();
  }
  if (sdate.value.pai == 2) {
    sdate.value.pai = 1;
    Show();
  }
};

onMounted(() => {
  Show();
});

const Show = () => {
  axios({
    url: 'http://localhost:64124/api/Text02/GetUserShow',
    method: 'get',
    params: sdate.value,
  })
    .then((res) => {
      console.log(res);
      plist.value = res.data.data.plist;
      count.value = res.data.data.count;
      pcount.value = res.data.data.pcount;
    })
    .catch((err) => {
      console.log(err);
    });
};

const ye = (val: any) => {
  if (val == 'a') {
    if (sdate.value.index == 1) {
      return;
    }
    sdate.value.index--;
  }
  if (val == 'b') {
    if (sdate.value.index == pcount.value) {
      return;
    }
    sdate.value.index++;
  }
  Show();
};
const y = (val: any) => {
  if (val == 'a') {
    sdate.value.index = 1;
  }
  if (val == 'b') {
    sdate.value.index = pcount.value;
  }
  Show();
};

const go = () => {
  if (cou.value < 0) {
    alert('没有这一页');
    return;
  }
  if (cou.value > pcount.value) {
    alert('没有这一页');
    return;
  }
  sdate.value.index = cou.value;
  Show();
};
</script>

<style scoped></style>
